//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Linq.Expressions;
using System.Reflection;
using EntLibContrib.Query.Commands;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Design;

namespace EntLibContrib.Query.Configuration
{
    /// <summary>
    /// <para>Represents the common configuration data for all commands.</para>
    /// </summary>
	public class CommandData : NameTypeConfigurationElement
	{
        private const string parameterSetNameProperty = "parameterSetName";
		
		/// <summary>
		/// Initializes a new instance of the <see cref="CustomCommandData"/> class.
		/// </summary>
		public CommandData()
		{
		}

        /// <summary>
        /// Initialize a new instance of the <see cref="CommandData"/> class with a name and a <see cref="ICommand"/>.
        /// </summary>
        /// <param name="type">The type of <see cref="ICommand"/>.</param>
        public CommandData(Type type)
            : this(null, type)
        {
        }

		/// <summary>
		/// Initializes a new instance of the <see cref="CustomCommandData"/> class.
		/// </summary>
		/// <param name="name">The command name.</param>
		/// <param name="type">The <see cref="P:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.NameTypeConfigurationElement.Type"/> that this element is the configuration for.</param>
        public CommandData(string name, Type type)
			: base(name, type)
		{
		}

        /// <summary>
        /// Gets or sets the parameter set name.
        /// </summary>
        /// <value>The parameter set name.</value>
        [ConfigurationProperty(parameterSetNameProperty, IsRequired = false)]
        [Reference(typeof(NamedElementCollection<ParameterSetData>), typeof(ParameterSetData))]
        [ResourceDescription(typeof(DesignResources), "ParameterSetNameDescription")]
        [ResourceDisplayName(typeof(DesignResources), "ParameterSetNameDisplayName")]
        public string ParameterSetName
        {
            get { return (string)base[parameterSetNameProperty]; }
            set { base[parameterSetNameProperty] = value; }
        }

        /// <summary>
        /// Creates a <see cref="TypeRegistration"/> instance describing the provider represented by 
        /// this configuration object.
        /// </summary>
        /// <returns>A <see cref="TypeRegistration"/> for the exception handler data</returns>
        public virtual TypeRegistration GetRegistration()
		{
			// Cannot make abstract for serialization reasons.
			throw new NotImplementedException("Must be implemented by subclasses.");
		}

        /// <summary>
        /// Builds a name with the supplied prefix. 
        /// </summary>
        /// <param name="prefix">Prefix to use when building a name</param>
        /// <returns>A name as string</returns>
        protected string BuildName(string prefix)
        {
            return prefix + "." + Name;
        }
	}
}
